package test_public;

import static org.junit.Assert.*;

import java.util.Vector;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import datamodel.rucksack.Rucksack;
import datamodel.rucksack.RucksackObject;

/**
 * Public test class for the Rucksack class
 * @author Peter
 *
 */
public class RucksackTest {
	
	
	static Rucksack r1;
	static Rucksack r2;
	static Rucksack r3;
	
	static RucksackObject o1;
	static RucksackObject o2;
	static RucksackObject o3;
	
	static Vector<RucksackObject> contents;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		o1 = new RucksackObject(0, 2);
		o2 = new RucksackObject(2, 5);
		o3 = o1;
	}

	@Before
	public void setUp() throws Exception {
		r1 = new Rucksack(11);
		r2 = new Rucksack(11);
		r3 = new Rucksack(10);
		contents = new Vector<RucksackObject>();
	}

	@Test
	public void testGetElements() {
		r1.insert(o1);
		r1.insert(o2);
		r1.insert(o3);
		contents.add(o1);
		contents.add(o2);
		contents.add(o3);
		assertEquals(contents, r1.getElements());
		r2.insert(o1);
		assertEquals(false, contents.equals(r2.getElements()));
	}

	@Test
	public void testGetCapacity() {
		assertEquals(11, r1.getCapacity());
		assertEquals(10, r3.getCapacity());
	}

	@Test
	public void testGetCurrentWeight() {
		assertEquals(0, r1.getWeight());
		r1.insert(o1);
		r1.insert(o2);
		r1.insert(o3);
		assertEquals(9, r1.getWeight());
	}

	@Test
	public void testGetCurrentValue() {
		assertEquals(0, r1.getValue());
		r1.insert(o1);
		r1.insert(o3);
		assertEquals(0, r1.getValue());
		r1.insert(o2);
		assertEquals(2, r1.getValue());
	}

	@Test
	public void testInsert() {
		assertEquals(false, r1.getElements().contains(o1));
		r1.insert(o1);
		assertEquals(true, r1.getElements().contains(o1));
		r1.insert(o1);
		contents.add(o1);
		contents.add(o1);
		assertEquals(true, contents.equals(r1.getElements()));
		r2.insert(o1);
		r2.insert(o2);
		r2.insert(o3);
		assertEquals(true, r2.insert(o3));
		assertEquals(false, r2.insert(o2));
	}

	@Test
	public void testEqualsObject() {
		assertEquals(true, r1.equals(r1));
		assertEquals(true, r1.equals(r2));
		assertEquals(true, r2.equals(r1));
		assertEquals(true, r2.equals(r2));
		r1.insert(o1);
		r1.insert(o1);
		r2.insert(o1);
		assertEquals(false, r1.equals(r2));
		r2.insert(o3);
		assertEquals(true, r1.equals(r2));
		r3.insert(o3);
		r3.insert(o1);
		assertEquals(false, r3.equals(r2));
		
		
	}

}
